use std::process::Command;
use std::path::Path;
use std::io::Error;
use std::fs;
use crate::read_file::read_file;

pub fn create_micro(project_name: String, git: String) -> Result<(), Error> {
    Command::new("cmd").arg("/c").arg("git clone -b micro").arg(git).output().expect("git命令执行失败了, 请检查git是否有配置为全局变量");
    let path = Path::new(&project_name);
    let template_path = Path::new("micro-template");

    if path.exists() {
        return Err(Error::new(std::io::ErrorKind::Other, "文件夹已经存在"));
    }
    fs::create_dir(path)?;

    let dir = fs::read_dir(template_path)?;
    for entry in dir {
        let entry = entry?;
        let path = entry.path();
        if path.is_file() {
            read_file(Path::new(&path.display()));
        }

        // 如果需要递归列出子目录中的文件，可以在这里添加递归调 用
    }

    Ok(())
}
